home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / acinclude.m4 < prev    next >
Encoding:
M4 Source File  |  1999-07-26  |  6.6 KB  |  268 lines

  1. dnl $Id: acinclude.m4,v 1.1.1.1 1999/05/18 15:33:41 dugsong Exp $
  2. dnl
  3. dnl     Libnet specific autoconf macros
  4. dnl     Copyright (c) 1998, 1999 Mike D. Schiffman <mike@infonexus.com>
  5. dnl                              route|daemon9 <route@infonexus.com>
  6. dnl     All rights reserved.
  7. dnl
  8.  
  9. dnl
  10. dnl Checks to see if this linux kernel has a working PF_PACKET
  11. dnl
  12. dnl usage:
  13. dnl
  14. dnl     AC_LIBNET_CHECK_PF_PACKET
  15. dnl
  16. dnl results:
  17. dnl
  18. dnl     HAVE_PF_PACKET (DEFINED)
  19. dnl
  20.  
  21. AC_DEFUN(AC_LIBNET_CHECK_PF_PACKET,
  22. [
  23.     AC_MSG_CHECKING(for PF_PACKET)
  24.     AC_CACHE_VAL(ac_libnet_have_pf_packet,
  25.  
  26.         [case "$target_os" in
  27.  
  28.         linux)
  29.                 ac_libnet_have_pf_packet = no
  30.                 ;;
  31.         *)
  32.  
  33.     cat > pf_packet-test.c << EOF
  34. #include <net/if.h>
  35. #if (__GLIBC__)
  36. #include <netinet/if_ether.h>
  37. #include <net/if_arp.h>
  38. #else
  39. #include <linux/if_arp.h>
  40. #include <linux/if_ether.h>
  41. #endif
  42. #if (PF_PACKET)
  43. #ifndef SOL_PACKET
  44. #define SOL_PACKET 263
  45. #endif  /* SOL_PACKET */
  46. #include <linux/if_packet.h>
  47. #endif
  48. #include "./include/libnet.h"
  49.  
  50. int
  51. main()
  52. {
  53. #if (PF_PACKET)
  54.     int fd;
  55.     struct sockaddr_ll sa;
  56.     struct ifreq ifr;
  57.     struct packet_mreq mr;
  58.     char *device ="lo";
  59.  
  60.     fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  61.     if (fd == -1)
  62.     {
  63.         printf("choked");
  64.         exit (EXIT_FAILURE);
  65.     }
  66.  
  67.     memset(&sa, 0, sizeof(sa));
  68.     strcpy(ifr.ifr_name, device);
  69.     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
  70.     {
  71.         printf("choked");
  72.         exit (EXIT_FAILURE);
  73.     }
  74.     sa.sll_family = AF_PACKET;
  75.     sa.sll_ifindex = ifr.ifr_ifindex;
  76.     sa.sll_protocol = htons(ETH_P_ALL);
  77.  
  78.     memset(&mr, 0, sizeof (mr));
  79.     mr.mr_ifindex = sa.sll_ifindex;
  80.     mr.mr_type = PACKET_MR_ALLMULTI;
  81.  
  82.     if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, (char *)&mr,
  83.             sizeof (mr)) < 0)
  84.     {
  85.         printf("choked\n");
  86.         exit (EXIT_FAILURE);
  87.     }
  88.     /* yay.  we made it and it workz! */
  89.     printf("yes");
  90. #else   /* PF_PACKET */
  91.     printf("no");
  92. #endif
  93.     exit (EXIT_SUCCESS);
  94. }
  95. EOF
  96.     ${CC-cc} -o pf_packet-test $CFLAGS pf_packet-test.c >/dev/null 2>&1
  97.  
  98.     # Oopz 4.3 BSD doesn't have this.  Sorry.
  99.     if test ! -x ./pf_packet-test ; then
  100.         ac_libnet_have_pf_packet=choked
  101.     else
  102.         ac_libnet_have_pf_packet=`./pf_packet-test`;
  103.     fi
  104.  
  105.     if test $ac_libnet_have_pf_packet = choked; then
  106.         AC_MSG_RESULT(test program choked... assuming no)
  107.     elif test $ac_libnet_have_pf_packet = yes; then
  108.         AC_DEFINE(HAVE_PF_PACKET)
  109.     fi
  110.  
  111.     if test $ac_libnet_have_pf_packet != choked; then
  112.         AC_MSG_RESULT($ac_libnet_have_pf_packet)
  113.     fi
  114.     rm -f pf_packet-test* core core.pf_packet-test
  115.     ;;
  116.     esac])
  117.  
  118. ])
  119.  
  120.  
  121. dnl
  122. dnl Looks for a previous libnet version and attempts to determine which verion
  123. dnl it is.  Version 0.8 was the first version that actually knew internally
  124. dnl what version it was.
  125. dnl
  126. dnl usage:
  127. dnl
  128. dnl     AC_LIBNET_CHECK_LIBNET_VERSION
  129. dnl
  130. dnl results:
  131. dnl
  132. dnl
  133. dnl
  134.  
  135. AC_DEFUN(AC_LIBNET_CHECK_LIBNET_VER,
  136. [
  137.     AC_CHECK_LIB(net, build_ip, AC_MSG_CHECKING(version) \
  138.  
  139.     if ! test -f $LIB_PREFIX/libnet.a; then
  140.         AC_MSG_RESULT($LIB_PREFIX/libnet.a doesn't exist)
  141.         AC_MSG_RESULT(previous libnet install lives elsewhere, you should probably find it)
  142.     else
  143.         __LIBNET_VERSION=`strings $LIB_PREFIX/libnet.a | grep "libnet version"\
  144.                 | cut -f3 -d" "`;\
  145.         if test -z "$__LIBNET_VERSION"; then
  146.             AC_MSG_RESULT(<0.8)
  147.         else
  148.             AC_MSG_RESULT($__LIBNET_VERSION)
  149.         fi
  150.     fi\
  151.     )
  152. ])
  153.  
  154.  
  155. dnl
  156. dnl Checks to see if this linux kernel uses ip_sum or ip_csum
  157. dnl (Pulled from queso)
  158. dnl
  159. dnl usage:
  160. dnl
  161. dnl     AC_LIBNET_CHECK_IP_CSUM
  162. dnl
  163. dnl results:
  164. dnl
  165. dnl     HAVE_STRUCT_IP_CSUM (DEFINED)
  166. dnl
  167.  
  168. AC_DEFUN(AC_LIBNET_CHECK_IP_CSUM,
  169. [
  170.     AC_MSG_CHECKING([struct ip contains ip_csum])
  171.     AC_TRY_COMPILE([
  172.         #define __BSD_SOURCE
  173.         #define _BSD_SOURCE
  174.         #include <sys/types.h>
  175.         #include <netinet/in.h>
  176.         #include <netinet/in_systm.h>
  177.         #include <netinet/ip.h>],
  178.         [
  179.             struct ip ip;
  180.             ip.ip_csum = 0;
  181.         ],
  182.         [AC_MSG_RESULT(yes);
  183.         AC_DEFINE(HAVE_STRUCT_IP_CSUM)],
  184.         [AC_MSG_RESULT(no);
  185.     ])
  186. ])
  187.  
  188. dnl
  189. dnl Checks to see if unaligned memory accesses fail
  190. dnl (Pulled from libpcap)
  191. dnl
  192. dnl usage:
  193. dnl
  194. dnl     AC_LBL_UNALIGNED_ACCESS
  195. dnl
  196. dnl results:
  197. dnl
  198. dnl     LBL_ALIGN (DEFINED)
  199. dnl
  200.  
  201. AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
  202.     [AC_MSG_CHECKING(if unaligned accesses fail)
  203.     AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
  204.         [case "$target_cpu" in
  205.  
  206.         alpha|hp*|mips|sparc)
  207.                 ac_cv_lbl_unaligned_fail=yes
  208.                 ;;
  209.  
  210.         *)
  211.                 cat >conftest.c <<EOF
  212. #                   include <sys/types.h>
  213. #                   include <sys/wait.h>
  214. #                   include <stdio.h>
  215.                     unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
  216.                     main()
  217.                     {
  218.                         unsigned int i;
  219.                         pid_t pid;
  220.                         int status;
  221.                         /* avoid "core dumped" message */
  222.                         pid = fork();
  223.                         if (pid <  0)
  224.                         {
  225.                             exit(2);
  226.                         }
  227.                         if (pid > 0)
  228.                         {
  229.                             /* parent */
  230.                             pid = waitpid(pid, &status, 0);
  231.                             if (pid < 0)
  232.                             {
  233.                                 exit(3);
  234.                             }
  235.                             exit(!WIFEXITED(status));
  236.                         }
  237.                         /* child */
  238.                         i = *(unsigned int *)&a[[1]];
  239.                         printf("%d\n", i);
  240.                         exit(0);
  241.                     }
  242. EOF
  243.                 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
  244.                     conftest.c $LIBS > /dev/null 2>&1
  245.                 # Oopz 4.3 BSD doesn't have this.  Sorry.
  246.                 if test ! -x conftest ; then
  247.                         dnl failed to compile for some reason
  248.                         ac_cv_lbl_unaligned_fail=yes
  249.                 else
  250.                         ./conftest > conftest.out
  251.                         if test ! -s conftest.out ; then
  252.                                 ac_cv_lbl_unaligned_fail=yes
  253.                         else
  254.                                 ac_cv_lbl_unaligned_fail=no
  255.                         fi
  256.                 fi
  257.                 rm -f conftest* core core.conftest
  258.                 ;;
  259.         esac])
  260.     AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
  261.     if test $ac_cv_lbl_unaligned_fail = yes ; then
  262.             AC_DEFINE(LBL_ALIGN)
  263.     fi
  264. ])
  265.  
  266.  
  267. dnl EOF
  268.